package com.da.landlord;

import java.io.File;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.googlecode.cswish.annotation.cm;
import com.ra.landlord.LandlordOwner;
import com.ra.landlord.LandlordOwnerUser;
import com.ra.landlord.TenantUser;

/**
 * 租客合约  agreementState
 * @author Peter.Z
 *
 */
@Entity
@Table(name="da_daagreement")
public class DaAgreement implements LandlordOwner {

	@cm("合约有效")
	public static final int AGREEMENT_STATE_VALID = 0;
	
	@cm("合约无效")
	public static final int AGREEMENT_STATE_INVALID = 1;

	@cm("月")
	public static final Integer RENT_CYCLE_TYPE_MONTH = 0;		//月
	
	@cm("年")
	public static final Integer RENT_CYCLE_TYPE_YEAR = 1;		//年
	
	@cm("一次性优惠")
	public static final int BREAK_TYPE_ONCE = 0;
	
	@cm("按月优惠")
	public static final int BREAK_TYPE_BYMONTH = 1;
	
	private Integer id;

	@cm("合约有效性 0表示有效 1表示无效")
	private Integer agreementState;
	
	@cm("合约编号")
	private String agreementNum;
	
	@cm("房间")
	private DaRoom room;

	@cm("房东")
	private LandlordOwnerUser landlordUser;
	
	@cm("承租人")
	private TenantUser tenantUser;

	@cm("租期") //租多久  1年 2年 3年
	private Integer rentPeriod;
	
	@cm("周期类型 ")		// 月，年
	private Integer rentCycleType;
	
	@cm("付款方式  押几")
	private Integer depositNum;
	
	@cm("付款方式  付几") //交租日期=起租日期+付几月  -提前多天
	private Integer payNum;

	@cm("起租日期")
	private Date rentBeginDate;

	@cm("到期日期")
	private Date rentEndDate;
	
	@cm("提前多少天 付款")
	private Integer advanceNum;
	
	@cm("押金") //租金*押几  可修改
	private BigDecimal deposit;

	@cm("租金  元/月")
	private BigDecimal rentPay;

	@cm("订金")
	private BigDecimal bookPay;
	
	@cm("优惠多少元")
	private BigDecimal breakFee;

	@cm("优惠类型 0一次性优惠 1按月优惠")
	private Integer breakType;
	
	@cm("备注")
	private String remark;

	@cm("收费周期")
	private Integer rentCycle;
	
	//transient
	private File photo;
	
	@cm("合约照片")
	private String photoFileName;
	
	@cm("房间所对应的帐单")
	private List<DaChargeBill> chargeBills;
	
	@cm("房间所对应的帐单")
	private List<DaChargeBillRecord> chargeBillRecords;

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne
	public DaRoom getRoom() {
		return room;
	}

	public void setRoom(DaRoom room) {
		this.room = room;
	}

	@ManyToOne(cascade = CascadeType.MERGE)
	public TenantUser getTenantUser() {
		return tenantUser;
	}

	public void setTenantUser(TenantUser tenantUser) {
		this.tenantUser = tenantUser;
	}


	public BigDecimal getDeposit() {
		return deposit;
	}

	public void setDeposit(BigDecimal deposit) {
		this.deposit = deposit;
	}

	public BigDecimal getRentPay() {
		return rentPay;
	}

	public void setRentPay(BigDecimal rentPay) {
		this.rentPay = rentPay;
	}

	public BigDecimal getBookPay() {
		return bookPay;
	}

	public void setBookPay(BigDecimal bookPay) {
		this.bookPay = bookPay;
	}

	public Integer getRentPeriod() {
		return rentPeriod;
	}

	public void setRentPeriod(Integer rentPeriod) {
		this.rentPeriod = rentPeriod;
	}

	public Date getRentBeginDate() {
		return rentBeginDate;
	}

	public void setRentBeginDate(Date rentBeginDate) {
		this.rentBeginDate = rentBeginDate;
	}

	public Date getRentEndDate() {
		return rentEndDate;
	}

	public void setRentEndDate(Date rentEndDate) {
		this.rentEndDate = rentEndDate;
	}

	public Integer getRentCycleType() {
		return rentCycleType;
	}

	public void setRentCycleType(Integer rentCycleType) {
		this.rentCycleType = rentCycleType;
	}


	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}


	@ManyToOne(fetch=FetchType.LAZY)
	@Override
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	@Override
	public void setLandlordUser(LandlordOwnerUser LandlordOwner) {
		this.landlordUser = LandlordOwner;
	}
	
	public Integer getAgreementState() {
		return agreementState;
	}

	public void setAgreementState(Integer agreementState) {
		this.agreementState = agreementState;
	}

	public Integer getDepositNum() {
		return depositNum;
	}

	public void setDepositNum(Integer depositNum) {
		this.depositNum = depositNum;
	}

	public Integer getPayNum() {
		return payNum;
	}

	public void setPayNum(Integer payNum) {
		this.payNum = payNum;
	}

	public Integer getAdvanceNum() {
		return advanceNum;
	}

	public void setAdvanceNum(Integer advanceNum) {
		this.advanceNum = advanceNum;
	}

	public String getAgreementNum() {
		return agreementNum;
	}

	public void setAgreementNum(String agreementNum) {
		this.agreementNum = agreementNum;
	}

	public BigDecimal getBreakFee() {
		return breakFee;
	}

	public void setBreakFee(BigDecimal breakFee) {
		this.breakFee = breakFee;
	}

	public Integer getBreakType() {
		return breakType;
	}

	public void setBreakType(Integer breakType) {
		this.breakType = breakType;
	}

	public Integer getRentCycle() {
		return rentCycle;
	}

	public void setRentCycle(Integer rentCycle) {
		this.rentCycle = rentCycle;
	}

	@Transient
	public File getPhoto() {
		return photo;
	}

	public void setPhoto(File photo) {
		this.photo = photo;
	}

	public String getPhotoFileName() {
		return photoFileName;
	}

	public void setPhotoFileName(String photoFileName) {
		this.photoFileName = photoFileName;
	}

	@OneToMany(mappedBy="agreement", fetch = FetchType.LAZY)
	@OrderBy("id desc")
	public List<DaChargeBill> getChargeBills() {
		return chargeBills;
	}

	public void setChargeBills(List<DaChargeBill> chargeBills) {
		this.chargeBills = chargeBills;
	}

	@OneToMany(mappedBy="agreement", fetch = FetchType.LAZY)
	@OrderBy("id desc")
	public List<DaChargeBillRecord> getChargeBillRecords() {
		return chargeBillRecords;
	}

	public void setChargeBillRecords(List<DaChargeBillRecord> chargeBillRecords) {
		this.chargeBillRecords = chargeBillRecords;
	}
	
}
